package masterjava.common.convertion;

import masterjava.common.logging.ServerLogger;
import org.springframework.core.convert.converter.Converter;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * User: Grigory Kislin
 * Date: 22/06/11
 */
public class InetAddressConverter implements Converter<String, InetAddress> {
    private static ServerLogger LOGGER = ServerLogger.get(InetAddressConverter.class);

    @Override
    public InetAddress convert(String source) {
        try {
            return InetAddress.getByName(source);
        } catch (UnknownHostException e) {
            throw LOGGER.getIllegalArgumentException("Illegal InetAddress " + source, e);
        }
    }
}
